package com.xinsoft.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xinsoft.entity.po.ScmPushBill;
import com.xinsoft.service.ScmPushBillService;
import com.xinsoft.mapper.ScmPushBillMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @author ZYM
* @description 针对表【scm_push_bill(推送单据)】的数据库操作Service实现
* @createDate 2023-10-30 14:48:25
*/
@Service
public class ScmPushBillServiceImpl extends ServiceImpl<ScmPushBillMapper, ScmPushBill>
    implements ScmPushBillService{
    /**
     * 获取待推送的单据
     * @param billType 单据类型
     * @param sourceId 源单id
     */
    @Override
    public Map<Integer, ScmPushBill> getWaitPushBillMap(Integer billType, Integer sourceId){
        List<ScmPushBill> pushBillList = this.list(Wrappers.lambdaQuery(ScmPushBill.class)
                .eq(ScmPushBill::getBillType, billType)
                .eq(ScmPushBill::getSourceId, sourceId)
                .eq(ScmPushBill::getStatus, 0));
        if (CollectionUtil.isNotEmpty(pushBillList)){
            return pushBillList.stream().collect(Collectors.toMap(ScmPushBill::getMaterialId, o -> o, (o1, o2) -> o2));
        }
        return null;
    }

    @Override
    public Map<Integer, ScmPushBill> getWaitPushBillMap(Integer billType, List<Integer> sourceIds) {
        List<ScmPushBill> pushBillList = this.list(Wrappers.lambdaQuery(ScmPushBill.class)
                .eq(ScmPushBill::getBillType, billType)
                .in(ScmPushBill::getSourceId, sourceIds)
                .eq(ScmPushBill::getStatus, 0));
        if (CollectionUtil.isNotEmpty(pushBillList)){
            return pushBillList.stream().collect(Collectors.toMap(ScmPushBill::getMaterialId, o -> o, (o1, o2) -> o2));
        }
        return null;
    }
}




